package top.taven.http;

import okhttp3.*;

public class OkHttpDemo {

    public static void main(String[] args) {

        try{

            //Demo1();

            Demo2();

        }catch (Exception e){
            e.printStackTrace();
        }


    }

    public static void Demo1() throws Exception {
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("https://4.ipw.cn")
                .build();

        Response response = client.newCall(request).execute();

        System.out.println(response.body().string());
    }

    public static void Demo2() throws Exception {

        String targetURL = "";


        String bodyContent = """
                   
                """;

        OkHttpClient client = new OkHttpClient();

        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        //RequestBody body = RequestBody.create(mediaType, payload);
        RequestBody body = RequestBody.create(mediaType, bodyContent);

        Request request = new Request.Builder().url(targetURL).post(body).build();

        Response response = client.newCall(request).execute();

        System.out.println(response.body().string());

    }


}